package com.heima.article.listener;

import com.alibaba.fastjson.JSON;
import com.heima.article.service.ApArticleConfigService;
import com.heima.common.constants.WmNewsMessageConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author shitou
 * @className ArticleIsDownListener
 * @description: 监听，接收数据
 */
@Component
@Slf4j
public class ArticleIsDownListener {

    @Resource
    private ApArticleConfigService apArticleConfigService;

    /**
     * 监听文章下架上架
     *
     * @param topic
     */
    @KafkaListener(topics = WmNewsMessageConstants.WM_NEWS_UP_OR_DOWN_TOPIC)
    public void onMessage(String topic) {
        if (StringUtils.isNotBlank(topic)) {
            // 解析topic
            Map map = JSON.parseObject(topic, Map.class);
            // 修改文章配置
            apArticleConfigService.updateConfigMap(map);
            log.info("监听文章下架上架已执行");
        }


    }


}
